if devid is None:
return 0
- self.writeDetails(config, devid, back, front)
+ (backpath, frontpath) = self.addStoreEntries(config, devid, back,
+ front)
- return devid
+ while True:
+ t = xstransact()
+ try:
+ if devid in self.deviceIDs(t):
+ if 'dev' in back:
+ dev_str = '%s (%d, %s)' % (back['dev'], devid,
+ self.deviceClass)
+ else:
+ dev_str = '%s (%s)' % (devid, self.deviceClass)
+
+ raise VmError("Device %s is already connected." % dev_str)
+
+ log.debug('DevController: writing %s to %s.', str(front),
+ frontpath)
+ log.debug('DevController: writing %s to %s.', str(back),
+ backpath)
+
+ t.remove2(backpath, HOTPLUG_STATUS_NODE)
+
+ t.write2(frontpath, front)
+ t.write2(backpath, back)
+
+ if t.commit():
+ return devid
+ except:
+ t.abort()
+ raise
def waitForDevices(self):
raise VmError("Device %s not connected" % devid)
- def deviceIDs(self):
+ def deviceIDs(self, transaction = None):
"""@return The IDs of each of the devices currently configured for
this instance's deviceClass.
"""
- return map(int, xstransact.List(self.frontendRoot()))
+ fe = self.frontendRoot()
+ if transaction:
+ return map(lambda x: int(x.split('/')[-1]), transaction.list(fe))
+ else:
+ return map(int, xstransact.List(fe))
## private:
- def writeDetails(self, config, devid, backDetails, frontDetails):
- """Write the details in the store to trigger creation of a device.
- The backend domain ID is taken from the given config, paths for
- frontend and backend are computed, and these are written to the store
- appropriately, including references from frontend to backend and vice
- versa.
+ def addStoreEntries(self, config, devid, backDetails, frontDetails):
+ """Add to backDetails and frontDetails the entries to be written in
+ the store to trigger creation of a device. The backend domain ID is
+ taken from the given config, paths for frontend and backend are
+ computed, and these are added to the backDetails and frontDetails
+ dictionaries for writing to the store, including references from
+ frontend to backend and vice versa.
+
+ @return A pair of (backpath, frontpath). backDetails and frontDetails
+ will have been updated appropriately, also.
@param config The configuration of the device, as given to
{@link #createDevice}.
'state' : str(xenbusState['Initialising'])
})
- log.debug('DevController: writing %s to %s.', str(frontDetails),
- frontpath)
- log.debug('DevController: writing %s to %s.', str(backDetails),
- backpath)
-
- while True:
- t = xstransact()
- try:
- t.remove2(backpath, HOTPLUG_STATUS_NODE)
-
- t.write2(frontpath, frontDetails)
- t.write2(backpath, backDetails)
-
- if t.commit():
- return
- except:
- t.abort()
- raise
+ return (backpath, frontpath)
def waitForBackend(self, devid):